﻿using System;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Caching;

namespace PJ.Data
{
    public abstract class EntityFragmentCache<T> : ObjectDataCache<T>, IEntityFragmentCache<T>
        where T : class, IEntityFragmentData
    {
        #region Constructor
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="cache">Cache manager</param>
        public EntityFragmentCache(ICacheManager cache)
            : base(cache)
        {
        }
        #endregion

        #region Inferface implementation

        /// <summary>
        /// Gets the owner's <see cref="IEntityFragmentData"/> child list.
        /// </summary>
        /// <param name="ownerId">Owner entity id</param>
        /// <returns>The array of item global ids if found else returns <see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="ownerId"/> is <see langword="null" /> or empty.</exception>
        public string[] FindFragments(string ownerId)
        {
            return FindCollection("Fragments", ownerId);
        }


        /// <summary>
        /// Adds the owner's <see cref="IEntityFragmentData"/> child list to the cache.
        /// </summary>
        /// <param name="ownerId">Owner entity id</param>
        /// <param name="globalIds">Collection of items global ids to add</param>
        /// <returns><paramref name="globalIds"/> value<see langword="null" /></returns>
        /// <exception cref="ArgumentNullException">If the passed <paramref name="ownerId"/> is <see langword="null" /> or empty. Or if <paramref name="collection"/> is <see langword="null" /></exception>
        public string[] AddFragments(string searchText, string[] globalIds)
        {
            AddCollection("Fragments", searchText, globalIds);
            return globalIds;
        }


        #endregion
    }
}
